package com.justindav1s.homecontrol;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * Created by justin on 10/11/2013.
 */
public class Buttons {

    private final Activity clientActivity;
    private final BluetoothEventListener bluetooth;
    public Button socket1_onButton = null;
    public Button socket1_offButton = null;
    public Button socket2_onButton = null;
    public Button socket2_offButton = null;
    public Button socket3_onButton = null;
    public Button socket3_offButton = null;
    public Button socket4_onButton = null;
    public Button socket4_offButton = null;

    public Buttons(Activity _clientActivity)   {
        clientActivity = _clientActivity;
        bluetooth = (BluetoothEventListener)_clientActivity;

    }

    public void setEnabledAll(boolean _enabled) {
        socket1_onButton.setEnabled(_enabled);
        socket1_offButton.setEnabled(_enabled);
        socket2_onButton.setEnabled(_enabled);
        socket2_offButton.setEnabled(_enabled);
        socket3_onButton.setEnabled(_enabled);
        socket3_offButton.setEnabled(_enabled);
        socket4_onButton.setEnabled(_enabled);
        socket4_offButton.setEnabled(_enabled);
    }


    public void initialise()    {

        socket1_onButton = (Button) clientActivity.findViewById(R.id.socket1_onButton);
        socket1_onButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 1 ON Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_1_ON.getBytes());
            }
        });

        socket1_offButton = (Button) clientActivity.findViewById(R.id.socket1_offButton);
        socket1_offButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 1 OFF Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_1_OFF.getBytes());
            }
        });

        socket2_onButton = (Button) clientActivity.findViewById(R.id.socket2_onButton);
        socket2_onButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 2 ON Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_2_ON.getBytes());
            }
        });

        socket2_offButton = (Button) clientActivity.findViewById(R.id.socket2_offButton);
        socket2_offButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 2 OFF Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_2_OFF.getBytes());
            }
        });

        socket3_onButton = (Button) clientActivity.findViewById(R.id.socket3_onButton);
        socket3_onButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 3 ON Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_3_ON.getBytes());
            }
        });

        socket3_offButton = (Button) clientActivity.findViewById(R.id.socket3_offButton);
        socket3_offButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 3 OFF Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_3_OFF.getBytes());
            }
        });

        socket4_onButton = (Button) clientActivity.findViewById(R.id.socket4_onButton);
        socket4_onButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 4 ON Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_4_ON.getBytes());
            }
        });

        socket4_offButton = (Button) clientActivity.findViewById(R.id.socket4_offButton);
        socket4_offButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(Constants.LOGTAG, "Socket 4 OFF Button Clicked !");
                bluetooth.sendCode(HomeEasyCodes.SOCKET_4_OFF.getBytes());
            }
        });

        setEnabledAll(false);

    }
}
